package org.whut.practice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.whut.practice.pojo.Execution;
import org.whut.practice.service.ExecutionService;
import org.whut.practice.utils.Response;

import java.util.HashMap;
import java.util.Map;

@Controller
public class ExecutionController {
    @Autowired
    ExecutionService executionService;

    @ResponseBody
    @PostMapping("/execution")
    public Map<String, Object> addExecution(@RequestBody Execution execution) {
        int count = executionService.addExecution(execution);
        return count > 0 ? Response.makeOkResponse(count, "Successfully add execution data") :
                Response.makeErrorResponse("Failed to add execution data");
    }
}
